﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ChineseSchool.BLL;
using ChineseSchool.Models.Hethong;

namespace ChineseSchool.UserControl.ThuNghiem
{
    public partial class SlideMainTop : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            lblSlideMain.Text = LoadBanner();
        }

        public string LoadBanner()
        {
            var strImage = "";
            List<M_Image> lstImage;
            if (Request.QueryString["id"] != null && Request.QueryString["id"] != "")
            {
                var menuId = int.Parse(Request.QueryString["id"]);
                var lstPage = (new B_Page()).GetBy_MenuID(menuId);
                var pageId = 0;
                if (lstPage.Count > 0)
                {
                    pageId = lstPage[0].pageID;
                }
                lstImage = (new B_Image()).GetBy_PageID(pageId);
                if (lstImage != null && lstImage.Count > 0)
                {
                    strImage += "<div class=\"carousel-inner\">";
                    for (var i = 0; i < lstImage.Count; i++)
                    {
                        if (i == 0)
                        {
                            strImage += "<div class=\"active item\">";
                        }
                        else
                        {
                            strImage += "<div class=\"item\">";
                        }
                        strImage += "    <div class=\"container slide-element\">";
                        strImage += "        <img src=\"" + lstImage[i].imageUrl + "\" alt=\" " + lstImage[i].imageName + "\" />";
                        strImage += "        <p><a href=\"" + lstImage[i].link + "\">" + lstImage[i].description + "</a></p>";
                        strImage += "    </div>";
                        strImage += "</div>";
                    }
                    strImage += "</div>";
                }
                else
                {
                    lstImage = (new B_Image()).GetBy_PageID(0);
                    if (lstImage != null && lstImage.Count > 0)
                    {
                        strImage += "<div class=\"carousel-inner\">";
                        for (var i = 0; i < lstImage.Count; i++)
                        {
                            if (i == 0)
                            {
                                strImage += "<div class=\"active item\">";
                            }
                            else
                            {
                                strImage += "<div class=\"item\">";
                            }
                            strImage += "    <div class=\"container slide-element\">";
                            strImage += "        <img src=\"" + lstImage[i].imageUrl + "\" alt=\" " + lstImage[i].imageName + "\" />";
                            strImage += "        <p><a href=\"" + lstImage[i].link + "\">" + lstImage[i].description + "</a></p>";
                            strImage += "    </div>";
                            strImage += "</div>";
                        }
                        strImage += "</div>";
                    }
                }
            }
            else
            {
                lstImage = (new B_Image()).GetBy_PageID(0);
                if (lstImage != null && lstImage.Count > 0)
                {
                    strImage += "<div class=\"carousel-inner\">";
                    for (var i = 0; i < lstImage.Count; i++)
                    {
                        if (i == 0)
                        {
                            strImage += "<div class=\"active item\">";
                        }
                        else
                        {
                            strImage += "<div class=\"item\">";
                        }
                        strImage += "    <div class=\"container slide-element\">";
                        strImage += "        <img src=\"" + lstImage[i].imageUrl + "\" alt=\" " + lstImage[i].imageName + "\" />";
                        strImage += "        <p><a href=\"" + lstImage[i].link + "\">" + lstImage[i].description + "</a></p>";
                        strImage += "    </div>";
                        strImage += "</div>";
                    }
                    strImage += "</div>";
                }
            }
            return strImage;
        }
    }
}